package com.pmcc.cj.service;

import com.pmcc.cj.entity.CjEvaluation;
import com.pmcc.cj.entity.CjOrder;
import com.pmcc.cj.repository.CjEvaluationRepository;
import com.pmcc.cj.repository.CjOrderRepository;
import com.pmcc.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Created by tomas on 2020/10/20.
 */
@Transactional
@Service
public class CjEvaluationService {
    @Autowired
    CjEvaluationRepository cjEvaluationRepository;
    @Autowired
    CjOrderRepository cjOrderRepository;

    public ResultBean addEvaluation(CjEvaluation model){
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        try {
            model.setCreateTime(new Date());
            cjEvaluationRepository.saveAndFlush(model);
//            //修改订单状态
//            CjOrder order=cjOrderRepository.findOne(model.getOrderId());
//            order.setPayStatus(5);
//            cjOrderRepository.saveAndFlush(order);
        }catch (Exception e){
            resultBean.setResultCode(ResultBean.FAIL);
        }
        return resultBean;
    }
}
